﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using Core.Contract.DataContract;
using Core.DAO;
using Data.BO;
using www.Models;

namespace Controllerss
{
    public class RageComic_MemeController
    {
        #region Value
        private readonly RageComic_MemeBO _menuBo = new RageComic_MemeBO();
        #endregion

        #region Ham Lay du lieu

        public IQueryable<RelaxRagcomicMemeDataContract> GetRagcomicMemeDataContracts()
        {
            using (var scope = new TransactionScope())
            {
                var lReturn = _menuBo.GetRagcomicMemeDataContracts();
                scope.Complete();
                return lReturn;
            }
        }
        #endregion

        #region Add

        public long Add(RelaxRagcomicMemeDataContract ragcomicMeme)
        {
            using (var scope = new TransactionScope())
            {
                long iD = 0;
                var menu = new MEME_RAGCOMIC
                {
                    image = ragcomicMeme.Image,
                    type = ragcomicMeme.Type,
                    active = ragcomicMeme.Active
                };
             
                _menuBo.Add(menu);
                var first = _menuBo.GetRagcomicMemeDataContracts().OrderByDescending(o => o.Id).FirstOrDefault();
                if (first != null)
                    iD = first.Id;
                scope.Complete();
                return iD;
            }
        }
        #endregion

        #region Update
        public Boolean Update(RelaxRagcomicMemeDataContract ragcomicMeme)
        {
            using (var scope = new TransactionScope())
            {
                var menu = new MEME_RAGCOMIC
                {
                    id = ragcomicMeme.Id,
                    image = ragcomicMeme.Image,
                    type = ragcomicMeme.Type,
                    active = ragcomicMeme.Active
                };
                _menuBo.Update(menu);
                scope.Complete();
                return true;
            }
        }
        #endregion

        #region Delete

        public Boolean Delete(List<long> lId)
        {
            using (var scope = new TransactionScope())
            {
                foreach (var id in lId)
                {
                    _menuBo.Delete(id);
                }
                scope.Complete();
                return true;
            }
        }
        #endregion
    }
}
